﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using CanalDeNoticiasMSDNv3.ViewModels;
using Microsoft.Phone.Tasks;

namespace CanalDeNoticiasMSDNv3
{
    public partial class RssDetailPage : PhoneApplicationPage
    {
        public RssDetailPage()
        {
            InitializeComponent();
        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            int index = int.Parse(this.NavigationContext.QueryString["id"]);
            string collectionName = this.NavigationContext.QueryString["collName"];

            if (string.CompareOrdinal(collectionName, "Noticias") == 0)
            {
                if (App.ViewModel != null && App.ViewModel.Noticias != null && App.ViewModel.Noticias.Count > 0)
                {

                    this.DataContext =
                    App.ViewModel.Noticias[index];
                }
            }
            else
            {
                if (App.ViewModel != null && App.ViewModel.Articulos != null && App.ViewModel.Articulos.Count > 0)
                {

                    this.DataContext =
                    App.ViewModel.Articulos[index];
                }

            }
        }

        private void ApplicationBarIconButton_Click(object sender, EventArgs e)
        {
            ElementoEntradaRss rss = DataContext as ElementoEntradaRss;
            if (rss != null)
            {
                new EmailComposeTask()
                {
                    Subject = "MSDN Video: " + rss.Title,
                    Body = rss.Link + "\n\n" + rss.Description
                }.Show();
            }
        }

        private void ApplicationBarIconButton_Click_1(object sender, EventArgs e)
        {
            ElementoEntradaRss rss = this.DataContext as ElementoEntradaRss;

            if (rss != null)
            {
                new WebBrowserTask() { URL = rss.Link }.Show();
            }
        }
    }
}